<?php
require dirname(__FILE__) . DIRECTORY_SEPARATOR . 'autoload.php';

use payClass\Datebase;
use payClass\QRcode;
use payClass\pay\Config;

/**
 * 出款
 */
class AsynNotice
{
    public static function paymentNotice()
    {
        $db     = new Datebase();

        $config = new Config();

        $param  = $db->param();

        // file_put_contents('data.txt', json_encode($param)."\r\n",FILE_APPEND);

        if ($param['mchid'] != Config::$merchant || $param['refCode'] != 1) exit('Fail');

        $sign = $param['sign'];

        unset($param['sign']);

        $sign = Config::getSignMsg($param);

        if ($sign != $param['sign']) exit('Sign verification failed, error code 001');

        $res = $db->withDrawRun(['order_number'=>$param['out_trade_no']]);

        if (!$res) exit('Sign verification failed, error code 002');

        exit('OK');
    }
}

AsynNotice::paymentNotice();
